package docker

import (
	"context"
	"github.com/docker/docker/api/types"
	"github.com/docker/docker/client"
	"io"
)

// var DockerImage = &dockerImage{
// }

type dockerImage struct {
}

func (receiver *dockerImage) List(cli *client.Client) ([]types.ImageSummary, error) {
	cli, err := Docker.NewClient()
	if err != nil {
		return []types.ImageSummary{}, err
	}

	images, err := cli.ImageList(context.Background(), types.ImageListOptions{})
	return images, err
}

func (receiver *dockerImage) Pull(cli *client.Client, remoteImage string) (io.ReadCloser, error) {
	cli, err := Docker.NewClient()
	if err != nil {
		return nil, err
	}

	reader, err := cli.ImagePull(context.Background(), remoteImage, types.ImagePullOptions{})
	return reader, err
}
func (receiver *dockerImage) Push(cli *client.Client, remoteImage string) (io.ReadCloser, error) {
	cli, err := Docker.NewClient()
	if err != nil {
		return nil, err
	}

	reader, err := cli.ImagePush(context.Background(), remoteImage, types.ImagePushOptions{})
	return reader, err
}
